import Vue from 'vue'
import VueRouter from 'vue-router'

import Home from '../components/Home.vue'
import Welcome from '../components/Welcome.vue'
import warning from '../components/Warning.vue'
import User from '../components/admin/UserList.vue'
import CostList from '../components/admin/CostList.vue'
import GroupT from '../components/admin/GroupT.vue'
import QuestionnaireT from '../components/admin/QuestionnaireT.vue'
import Statistics from '../components/answer/Statistics.vue'

//引入表单组件
import AnswerMgt from '../components/answer/AnswerMgt.vue'
import unAnswerMgt from '../components/answer/unAnswerMgt.vue'
import AnswerQst from '../components/answer/AnswerQst.vue'
import AnswerManage from '../components/answer/AnswerManage.vue'
import GroupManagement from '../components/admin/GroupManagement.vue'
import GroupMembers from '../components/admin/GroupMembers.vue'
import QuestionnaireList from '../components/questionnaire/QuestionnaireList.vue'
import CreateQuestionniare from '../components/questionnaire/paperEditor/index.vue'
import GarbageList from '../components/questionnaire/GarbageList.vue'
import Template from '../components/questionnaire/Template.vue'
import EditTemplate from '../components/questionnaire/EditTemplate.vue'
import Screen from '../components/questionnaire/Screen.vue'

// 登录界面组件引入
import Login from '../components/login/Login.vue'
import Registor from '../components/login/Register.vue'
import LoginPhone from '../components/login/LoginPhone'
import PhoneFind from '../components/login/PhoneFind'
import PasswordFind from '../components/login/PasswordFind'
import PasswordReset from '../components/login/PasswordReset'


Vue.use(VueRouter)

const routes = [
  {
    path:"/",redirect:"/login"
  },
  {
    path:"/login",
    component:Login
  },
  {
    path:"/Register",
    component:Registor
  },
  {
    path:"/Login-Phone",
    component:LoginPhone
  },
  {
    path:"/PasswordFind",
    component:PasswordFind
  },
  {
    path:"/PasswordReset",
    component:PasswordReset
  },
  {
    path:"/PhoneFind",
    component:PhoneFind
  },
  {
    path:"/warning",
    component:warning
  },
  {
    path:"/answerq",
    component:AnswerQst
  },
  {
    path:"/statistics",
    component:Statistics
  },
 



  // 进入主界面操作
  {
    path:"/home",
    component:Home,
    redirect:"/welcome",
    children:[
      {path:"/welcome",component:Welcome,},
      {path:"/user",component:User,},
      {path:"/groups",component:GroupManagement},
      {path:"/groupmembers",component:GroupMembers},
      {path:"/cost",component:CostList},
      {path:"/groupt",component:GroupT},
      {path:"/questionnairet",component:QuestionnaireT},

      {path:"/sendq",component:QuestionnaireList},
      {path:"/answered",component:AnswerMgt},
      {path:"/unanswered",component:unAnswerMgt},
      {path:"/answeredManage",component:AnswerManage},
      
      {path:"/garbage",component:GarbageList},
      {path:"/CreateQuestionnaire",component:CreateQuestionniare},
      {path:"/template",component:Template},
      {path:"/editTemplate",component:EditTemplate},
      {path:"/screen",component:Screen},


    ]
  },
]

const router = new VueRouter({
  routes
})

// // 挂载路由导航守卫
// router.beforeEach((to,from,next)=>{
//   // to 将要访问
//   // from 从哪访问
//   // next 接着干 next(url) 重定向到url上，next()继续访问 to 路径
//   if(to.path=='/login'){
//     return next();
//   }else{
//     //获取user
//     next()
//     const userFlag = window.sessionStorage.getItem("name");// 取出当前用户
//     if(!userFlag){
//       return next('/warning');// 无值，返回登录页面
//     }else{
//       next();
//     }
//   }
// })

// 出现问题的时候使用
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}

export default router
